const isProduction = process.env.NODE_ENV === 'production';
const cdn = {
  css: [],
  js: [
    // local
    '/cdn/vue.2.6.14.runtime.min.js',
    '/cdn/vue-i18n.8.25.1.min.js',
    '/cdn/vue-router.3.5.2.min.js',
    '/cdn/vuex.3.6.2.min.js',
    '/cdn/axios.0.21.1.min.js',
    '/cdn/element-ui.2.15.6.min.js',
    '/cdn/nprogress.0.2.0.min.js',

    // bootcdn
    // 'https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.runtime.min.js',
    // 'https://cdnjs.cloudflare.com/ajax/libs/vue-i18n/8.25.1/vue-i18n.min.js',
    // 'https://cdn.bootcdn.net/ajax/libs/vue-router/3.5.2/vue-router.min.js',
    // 'https://cdn.bootcdn.net/ajax/libs/vuex/3.6.2/vuex.min.js',
    // 'https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js',
    // 'https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.15.7/index.min.js',
    // 'https://cdn.bootcdn.net/ajax/libs/nprogress/0.2.0/nprogress.min.js'
  ]
}

module.exports = {
  // outputDir: '../prod/dist',
  productionSourceMap: false,
  transpileDependencies: ['element-ui', 'ele-admin'],
  devServer: {
    port: 8090,
    proxy: {
      '/backstage': {
        target: process.env.VUE_APP_API_DOMAIN,
        changeOrigin: true,
        ws: true,
        // pathRewrite: {
        //   '^/api': '',
        // },
      },
    },
  },
  chainWebpack: (config) => {
    config.plugins.delete('prefetch');
    // 生产环境注入cdn
    if (isProduction) {
      config.plugin('html').tap(args => {
        args[0].cdn = cdn;
        return args;
      });
    }
  },
  configureWebpack: config => {
    // 用cdn方式引入
    if (isProduction) {
      config.externals = {
        'vue': 'Vue',
        'vuex': 'Vuex',
        'axios': 'axios',
        'nprogress': 'NProgress',
        'vue-i18n': 'VueI18n',
        'element-ui': 'ELEMENT',
        'vue-router': 'VueRouter',
      }
    }
  },
  css: {
    loaderOptions: {
      sass: {
        sassOptions: {
          outputStyle: 'expanded'
        }
      }
    }
  }
}
